package cn.com.cifi.mars.web.aop;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;

/**
 * dao日志 统计耗时
 */
@Aspect
@Configuration
@Order(1)
public class DaoLogHandler {

	private final Logger LOGGER = LogManager.getLogger(DaoLogHandler.class);

	/**
	 * 切入点
	 */
	@Pointcut("execution(* cn.com.cifi.mars.mapper..*.*(..))")
	public void api() {
	}

	/**
	 * 环绕
	 *
	 * @return
	 */
	@Around("api()")
	public Object around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
		long s = System.currentTimeMillis();
		try {
			return proceedingJoinPoint.proceed(proceedingJoinPoint.getArgs());
		} finally {
			LOGGER.info(
					proceedingJoinPoint.getSignature().toString() + ",耗时：" + (System.currentTimeMillis() - s) + " ms");
		}
	}
}
